package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.util.DateUtils;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormBidNoticeThanks;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormBidNoticeThanks;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormBidNoticeThanksMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtWFlowFormBidNoticeThanksMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormBidNoticeThanksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 流程表单-中标通知书与感谢信 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormBidNoticeThanksServiceImpl extends ServiceImpl<WFlowFormBidNoticeThanksMapper, WFlowFormBidNoticeThanks> implements WFlowFormBidNoticeThanksService {
    @Autowired
    private ExtWFlowFormBidNoticeThanksMapper extWFlowFormBidNoticeThanksMapper;
    @Override
    public List<ExtWFlowFormBidNoticeThanks> getExtByFormIdAndType(String formId, Integer type) {
        WFlowFormBidNoticeThanks wFlowFormBidNoticeThanks = new WFlowFormBidNoticeThanks();
        wFlowFormBidNoticeThanks.setFlowFormId(formId);
        wFlowFormBidNoticeThanks.setNoticeType(type);
        return  extWFlowFormBidNoticeThanksMapper.getByEntity(wFlowFormBidNoticeThanks);
    }

    @Override
    public List<ExtWFlowFormBidNoticeThanks> getExtByFormIdAndTypeAndSupplierId(String formId, Integer type, String supplierId) {
        WFlowFormBidNoticeThanks wFlowFormBidNoticeThanks = new WFlowFormBidNoticeThanks();
        wFlowFormBidNoticeThanks.setFlowFormId(formId);
        wFlowFormBidNoticeThanks.setNoticeType(type);
        wFlowFormBidNoticeThanks.setSupplierId(supplierId);
        return  extWFlowFormBidNoticeThanksMapper.getSupplierDataByEntity(wFlowFormBidNoticeThanks);
    }

    @Override
    public Date setDowned(String id) {
        Date now = DateUtils.getNow();
        WFlowFormBidNoticeThanks wFlowFormBidNoticeThanks = new WFlowFormBidNoticeThanks();
        wFlowFormBidNoticeThanks.setDownloadTime(now);
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("id",id).isNull("download_time");
        if(!update(wFlowFormBidNoticeThanks,entityWrapper))
            now = null;
        return now;
    }

    @Override
    public void setSendTimeByFormId(String formid) {
        WFlowFormBidNoticeThanks wFlowFormBidNoticeThanks = new WFlowFormBidNoticeThanks();
        wFlowFormBidNoticeThanks.setSendTime(DateUtils.getNow());
        update(wFlowFormBidNoticeThanks,new EntityWrapper<WFlowFormBidNoticeThanks>().eq("flow_form_id",formid));
    }
}
